
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.HashMap"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
 <head>
  <title>login page</title>
	<link rel="stylesheet" href="css/jquery.mobile-1.3.2.min.css" />
	<link rel="stylesheet" href="css/SearchAnything.css" />
    <style type="text/css">
		.dealerTable {
			border: none;
			border-collapse: collapse;
			width: 100%;
			text-shadow: 0px 0px #ff0000;
		}
		
		.dealerTable td {
			border-left: 1px solid #000;
			border-right: 1px solid #000;
			border:  0px;
		}
</style>
    <script type="text/javascript"  src="js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="js/jquery.mobile-1.3.2.min.js"></script>
	
	
  <script type="text/javascript">
  $(document).ready(function(){
	 $.mobile.ajaxEnabled = false;

	 $('.hidebtn').bind('click',function(){
		 	
		 $(this).parent().html("<a class='showbtn' barcode='"+$(this).attr('barcode')+"' href='#'>Show</a>");		 
		 });
	 	
	 $('.showbtn').bind('click',function(){
		 
		 $(this).parent().html("<a class='hidebtn' barcode='"+$(this).attr('barcode')+"' href='#'>Hide</a>");
	 });

	$(document).delegate('.hidebtn','click',function(){
			//Make ajax call
					
			$(this).parent().html("<a class='showbtn' barcode='"+$(this).attr('barcode')+"' href='#'>Show</a>");
			showOrHideBusiness($(this).attr('barcode'),"YES");
			}
		);

		$(document).delegate('.showbtn','click',function(){
		
			$(this).parent().html("<a class='hidebtn' barcode='"+$(this).attr('barcode')+"' href='#'>Hide</a>");
			showOrHideBusiness($(this).attr('barcode'),"NO");	
			}
		);
		
   });
	  
	function submitForm(barcode){
		$('#submitbarcode').val(barcode);
		$('#submitbarcodeform').submit();		
	}
	
	function showOrHideBusiness(barcodedata,hide){
        $.get("http://server:8080/parvati/Getnameservlet",{methodetocall:'showorhide',showorhide:hide,barcode:barcodedata},function(res,code){
			
        });

	}

	   </script>
 </head>
 <body>
  <div data-role="page" id="home">  
   <div data-position="fixed" data-role="header" data-theme="b">   
    <a href="menudisplay" data-role="buttun" data-icon="home">Menu</a>
    <h1>  
     Search Page<%=session.getAttribute("username") %>
    </h1>  
   </div>  
   <div align="center" data-role="content">
   
   <h1>PARVATI SOLVENTS EXTRACTION PVT LTD</h1>
			<h3>GUT NO.76, KHADGAON,TALUKA: BADNAPUR,DISTRICT:JALNA-431203,MAHARASHTRA,INDIA</h3>
   <form action="searchresult" method="POST">
   	Search By <%=session.getAttribute("searchby") %>
   	<input type="hidden" name="searchText" value="<%=session.getAttribute("searchtext") %>"/>
   	<input type="hidden" name="serchBy" value="<%=session.getAttribute("searchby") %>"/>
   	Search Result for <%=session.getAttribute("searchtext") %>
   	<div id="dateDiv">
   	<table>
   	<tr>
    	<td><input type="date" class="" name="startDate" /></td><td><input type="date" name="endDate"/></td>
    	<td><input type="submit" value="Search"/></td>
    </tr>        
    </table>
    </div>
   </form>
  </div>
  	<%
  HashMap dataMapComplete =(HashMap) session.getAttribute("completeData"); 
  if(null == dataMapComplete ){ 
	  out.println("<div style='color:red;'>No Search criteria found</div>");
  }else{
	  out.println("<div style='color:green;'>Search item</div>");
	  HashMap dealarMap = (HashMap)dataMapComplete.get("dealerData");
	  if(null!=dealarMap){
		  out.println("Dealer Data:<br>");
		  out.println("<table border='1' class='dealerTable'> ");
		  String dealerDataString = "<tr><td>Name: <br/>"+dealarMap.get("dataName")+"<td>Address:<br/>"+dealarMap.get("dataAddress")+","+dealarMap.get("dataCity")+","+dealarMap.get("dataDistrict")+","
				  +dealarMap.get("dataState")+","+dealarMap.get("dataCountry")+","+dealarMap.get("dataZipcode")+"<td>UniqueId<br/>"+dealarMap.get("dataUniqueId")+"</td>"+"<td> Contact:<br/>"+dealarMap.get("dataContact")+"<td>"
				  +"Email:<br/>"+dealarMap.get("dataEmailId")+"</td></tr>";
		  out.println(dealerDataString);
		  out.println("</table>");
	  }
	 
	 Iterator iterator = dataMapComplete.entrySet().iterator();
	 
	// if((null !=dealarMap) && (dealarMap.containsKey("dealerData") && dealarMap.size()>1) || (!dealarMap.containsKey("dealerData") && dealarMap.size()>0)){
	 out.println("<br>Bussineess Data<br><table data-role='table' id='table-column-toggle' data-mode='columntoggle' class='ui-responsive table-stroke'>"+
             "<thead>"+
     	"<tr>"+
       	"<th>Date</th>"+
       	"<th data-priority='2'>Brocker Name</th>"+
       	"<th data-priority='3'>Customer Name</th>"+
       	"<th data-priority='5'>Commision Agent</th>"+
       	"<th data-priority='1'><abbr title='Rotten Tomato Rating'>No of Bags</abbr></th>"+
       	"<th data-priority='5'>PO Number</th>"+
       	"<th data-priority='5'>Net Weight</th>"+
      
    " </tr>"+
   "</thead>"+
   "<tbody>");
	 
	 String userrole = (String)session.getAttribute("userrole");
	 while(iterator.hasNext()){
		 Map.Entry dataMap = (Map.Entry) iterator.next();
		  HashMap businessMap = (HashMap) dataMap.getValue();
		 // System.out.println("Bussiness Date"+businessMap.get("businessdate") +":Dealer data"+dataMap.getKey());
		  String dateFormated = "";
		  System.out.println("BusinessData :"+businessMap);
		  if(null!=businessMap){
		  if(null!=(businessMap.get("businessdate"))){
		   dateFormated = (businessMap.get("businessdate").toString());
		  }
		 	if(!dataMap.getKey().equals("dealerData") && !"".equalsIgnoreCase(dateFormated)){
		 		if(!businessMap.get("businessHide").toString().toUpperCase().equals("YES") || userrole.equalsIgnoreCase("superadmin")){
		 		out.println("<tr><th><a href='javascript:submitForm(\""+dataMap.getKey()+"\")'>"+dateFormated.subSequence(0, 4)+"-"+dateFormated.subSequence(4, 6)+"-"+dateFormated.subSequence(6, 8)+"</a></th>"+
		 		"<td>"+businessMap.get("businessBrokerName")+"</td>"+
		 		"<td>"+businessMap.get("businesscustomerName")+"</td>"+
		 		"<td>"+businessMap.get("businessCommisionAgentName")+"</td>"+
		 		"<td>"+businessMap.get("businessNoOfBags")+"</td>"+
		 		"<td>"+businessMap.get("businessPONo")+"</td>"+
		 		"<td><abbr title='Net Weight:"+businessMap.get("businessNetWeight")+"&#013Gross Weight:"+businessMap.get("businessGrossWeight")+"&#013Tare Weight"+businessMap.get("businessTareWeight")+"'>"+businessMap.get("businessNetWeight")+"</td>"+
		 		"<td><abbr title='Net Weight:"+businessMap.get("businessNetWeight")+"&#013Gross Weight:"+businessMap.get("businessGrossWeight")+"&#013Tare Weight"+businessMap.get("businessTareWeight")+"'>"+"</td>");
		 		if(null!=session.getAttribute("userrole") && session.getAttribute("userrole").equals("superadmin") && null!=businessMap.get("businessHide")){	
		 			System.out.print("Is bussineess hiddedn..."+businessMap.get("businessHide"));
		 			if(businessMap.get("businessHide").toString().toUpperCase().equals("YES"))
		 				out.println("<td><a class='showbtn' barcode='"+dataMap.getKey()+"' href='#'>Show</a></td>");
		 			else
		 				out.println("<td><a class='hidebtn' barcode='"+dataMap.getKey()+"' href='#'>Hide</a></td>");
		 		}
		 		out.println("</tr>");
		 		System.out.println("if ends");
		 	}
		 	}
		 	System.out.println("Loop ends");
		  }
	 }
	 	out.println("</tbody></table>");
	 	//out.println("<script>$('.businessTable').listview('refresh'); alert('refreshing.....')</script>");
	// }else{
	//	 out.println("<div color='red'>No data Found please change search criteria</div>"); 
	// }
  } %>
  
  </div>
  <form id="submitbarcodeform" method="post" action="viewinfo">
  	<input type="hidden" name="barcode" id="submitbarcode" value="">
  </form>
  
    </body>
</html>